package com.example.administrator.activity.parcitise.Activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.administrator.activity.R;

public class RegisterActivity extends AppCompatActivity {
    private EditText ed_name,ed_phone;
    private Button bth_submit,bth_reset;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        /*
        1.关联布局文件
         */
        setContentView(R.layout.activity_register);

        /*
        2.关联控件
         */
        ed_name=findViewById(R.id.name1);
        ed_phone=findViewById(R.id.phone1);
        bth_submit=findViewById(R.id.submit);
        bth_reset=findViewById(R.id.reset);
        /*
        3.按钮的点击事件
         */

        /*
        事件
         */

        View.OnClickListener click=new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()){
                    case R.id.submit:
                        String s=ed_name.getText().toString()+" "+ed_phone.getText().toString();
                        Toast.makeText(RegisterActivity.this,s, Toast.LENGTH_LONG).show();
                        break;
                    case R.id.reset:
                        ed_name.setText(null);
                        ed_phone.setText(null);
                /*
                让ed_name获取焦点
                 */
                        ed_name.requestFocus();
                        break;
                }

            }
        };


        /*
        按钮绑定上事件
         */
        bth_submit.setOnClickListener(click);
        bth_reset.setOnClickListener(click);
    }
}
